package com.ruiboyun.liveapp.util.tool;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

/**
 * Created by 吴世芊 on 2016/11/24.
 * Update by  on
 * 公司:杭州无尽信息科技有限公司
 * 邮箱：apple9302@126.com
 * Description:
 */

public class KeyboardUtils {
    public static void hideKeyboard(final Activity act) {
        if (null == act) {
            return;
        }
        if (null == act.getCurrentFocus()) {
            return;
        }
        ((InputMethodManager) act
                .getSystemService(Context.INPUT_METHOD_SERVICE))
                .hideSoftInputFromWindow(
                        act.getCurrentFocus().getWindowToken(), 0);
    }

    public static void hideKeyboard(View v) {
        InputMethodManager imm = (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(v.getApplicationWindowToken(), 0);
    }

    public static void showKeyboard(View v) {
        InputMethodManager imm = (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
    }
}
